﻿


var Class = {
    create: function (classObj) {
        var args = jQuery.makeArray(arguments);
        {
            args.shift();
            var tempclassObj = function (params) {
                this.initialize.apply(this, params);
                this.initializeDOM.apply(this, params);
                this.initializeControl.apply(this, params);
                this.initializeEvent.apply(this, params);
                this.pageLoad.apply(this, params)
            };
        }
        classObj.initialize = classObj.initialize || jQuery.noop;
        classObj.initializeDOM = classObj.initializeDOM || jQuery.noop;
        classObj.initializeControl = classObj.initializeControl || jQuery.noop;
        classObj.initializeEvent = classObj.initializeEvent || jQuery.noop;
        classObj.pageLoad = classObj.pageLoad || jQuery.noop;

        tempclassObj.prototype = classObj;
        var result = new tempclassObj(args);
        return result;
    }
}

//jquery类扩展
$.extend({
    strFilter: function (str) {
        str = $.trim(str).replace(/[~'"!<>@#$%^&*()-+_=:]/g, "");
        return str;
    },
    trimend: function (str, char) {
        if (str == null || str == "") return str;
        var regExp = new RegExp(char + "$");
        return str.replace(regExp, "");
    },
    bindForm: function (params) {
        //提供input[text,checkbox,radio]、areatext的数据绑定
        params.form.find("input,select,textarea,label").each(function () {
            var input_name = $.trim($(this).attr('name'));
            if (input_name) {
                var input_value = eval("params.model." + input_name);
                if (input_name) {
                    if (this.type == "checkbox") {
                        $(this).attr("checked", input_value == "True" || input_value == "true" || input_value == true);
                    }
                    else if (this.type == "radio") {
                        $("input[name=" + this.name + "][value=" + input_value + "]").attr("checked", true);
                    }
                    else if ($(this).is("select")) {
                        $(this).find("option[value=" + input_value + "]").attr("selected", true)
                    }
                    else if ($(this).is("label")) {
                        $(this).html(input_value);
                    }
                    else
                        $(this).val(input_value);
                }
            }
        });
    }
});


//格式化时间格式
function dateFormatter(value) {
    if (value == null || value == "") return value;
    var date;
    if (value.toString().indexOf("Date") > -1) {
        date = new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
    }
    else
        date = new Date(value);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    var t = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d) + ' ';
    return t;

}


function timeFormatter(value) {
    if (value == null || value == "") return value;
    var date;
    if (value.toString().indexOf("Date") > -1) {
        date = new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
    }
    else
        date = new Date(value);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    var t = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d) + ' ';

    var hh = date.getHours();
    var mm = date.getMinutes();
    var ss = date.getSeconds();
    t += (hh < 10 ? ('0' + hh) : hh) + ':' + (mm < 10 ? ('0' + mm) : mm) + ':' + (ss < 10 ? ('0' + ss) : ss);
    return t;
}